import { Message } from "fawkes-lib";
/**
 * @description: 格式化时间
 * @param {*} seconds
 * @return {*}
 */
export const formatSeconds = (seconds) => {
  const days = Math.floor(seconds / 86400);
  const hours = Math.floor((seconds % 86400) / 3600);
  const minutes = Math.floor((seconds % 3600) / 60);
  const secs = Math.floor(seconds % 60);
  let timeString = "";

  if (days > 0) timeString += `${days}天`;
  if (hours > 0) timeString += `${hours}小时`;
  if (minutes > 0) timeString += `${minutes}分钟`;
  if (secs > 0) timeString += `${secs}秒`;

  return timeString || "0秒";
};

/**
 * @description: 格式化字节
 * @param {*} bytes
 * @param {*} decimals
 * @return {*}
 */
export const formatBytes = (bytes, decimals = 2) => {
  if (bytes === 0) return "0 B";

  const k = 1024;
  const dm = decimals < 0 ? 0 : decimals;
  const sizes = ["B", "KB", "MB", "GB", "TB", "PB"];
  const i = Math.floor(Math.log(bytes) / Math.log(k));

  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
};
export function copyText(textToCopy) {
  var input = document.createElement("input");

  //将input的值设置为需要复制的内容

  input.value = textToCopy;

  //添加input标签

  document.body.appendChild(input);

  //选中input标签

  input.select();

  //执行复制

  document.execCommand("copy");

  //成功提示信息

  Message({
    message: "复制成功！",
    type: "success",
  });

  //移除input标签

  document.body.removeChild(input);
}
